#include "process.h"

#define LENGTH 101
#define LABLE '#'


void Fflushprocess(double target, double current)
{
    //定义光标
    const char* symb = "/|-\\";
    static int index = 0;
    const int len = strlen(symb);
    //更新出进度
    double rate = (current / target) * 100.0;  //5.0 / 100.0 = 0.05 -> 5%
    //取整递增#
    int cnt = (int)rate;
    //更新进度条
    char bar[LENGTH];
    memset(bar, '\0', sizeof(bar));
    for(int i = 0; i < cnt; i++)
        bar[i] = LABLE;
    //打印进度条
    printf("[%-100s][%.1lf%%][%c]\r", bar, rate, symb[index++]);
    index %= len;
    fflush(stdout);
}


//void Process()
//{
//    const char* symb = "/-|\\";
//    int s_len = strlen(symb);
//    char bar[LENGTH];
//    memset(bar, '\0', sizeof(bar));
//    int cnt = 0;
//    while(cnt <= 100)
//    {
//        printf("[%-100s][%d%%][%c]\r", bar, cnt, symb[cnt % s_len]);
//        fflush(stdout);
//        bar[cnt++] = LABLE;
//        usleep(20000);
//    }
//    printf("\n");
//}

